home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_056 / mcad / mp / source / gethowto.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  153 lines

  1. #include <stdio.h>
  2. #include <exec/types.h>
  3. #include "struct.h"
  4. #include "plot.h"
  5.  
  6. extern int debug;
  7.  
  8. extern char *gets();
  9. extern char *getwrd();
  10.  
  11. void GetHowTo(Pict)
  12. struct Pict *Pict;
  13. {
  14.    short i;
  15.    static short firstcall = TRUE;
  16.    char s[100], *sp, *wp; /* STRING BUFFER, STRING POINTER, WORD POINTER */
  17.    struct Plot *Plot;
  18.  
  19.    if (debug) {
  20.       printf("GetHowTo: entry\n");
  21.       printf("   Pict->ErrBar = %d\n",Pict->ErrBar);
  22.       printf("   Pict->ShowErr = %d\n",Pict->ShowErr);
  23.    }
  24.    if (firstcall) {
  25.       firstcall = FALSE;
  26.       /*** ESTABLISH DEFAULTS ***/
  27.       Pict->Grid = FALSE;
  28.       Pict->ShowErr = Pict->ErrBar;
  29.       Pict->Tics->NX = Pict->Tics->NY = 5;
  30.    }
  31.  
  32.    /*** GET PLOTTING INSTRUCTIONS ***/
  33.    printf("\x9b2m%d\x9bm data sets.\n",Pict->NPlt);
  34.    printf("Enter \x9b2mhow_to string\x9bm (? for help) > ");
  35.    sp = gets(s);
  36.    while (*sp == '?') {
  37.       printf("\n\tA \x9b2mhow_to STRING\x9bm is:\n");
  38.       printf("\t  an optional \x9b2mswitch string\x9bm followed by one of:\n");
  39.       printf("\t     1)  \x9b2mreturn\x9bm   default plot of all data sets        .OR.\n");
  40.       printf("\t     2)    \x9b2m!p\x9bm     default point plot of all data sets  .OR.\n");
  41.       printf("\t     3)  one or more \x9b2mhow_to\x9bm WORDs separated by spaces\n\n");
  42.       printf("\tA \x9b2mswitch string\x9bm is \x9b2m/\x9bm followed by any of:\n");
  43.       printf("\t     \x9b2md\x9bm(\x9b2mD\x9bm)   debug on (off)\n");
  44.       printf("\t     \x9b2me\x9bm(\x9b2mE\x9bm)   error bars plotted (not plotted)\n");
  45.       printf("\t     \x9b2mg\x9bm(\x9b2mG\x9bm)   grid drawn (not drawn) on plot\n");
  46.       printf("\t     \x9b2mt#     #\x9bm divisions for tic marks or grid\n\n");
  47.       printf("\tA \x9b2mhow_to WORD\x9bm is \x9b2m*\x9bm or \x9b2m-\x9bm or [\x9b2m#1\x9bm]\x9b2mt\x9bm[\x9b2m#2\x9bm]  where:\n");
  48.       printf("\t     \x9b2m*\x9bm   gets default plot for a data set\n");
  49.       printf("\t     \x9b2m-\x9bm   skips (does not plot) a data set\n");
  50.       printf("\t     []  encloses an optional parameter\n");
  51.       printf("\t     \x9b2m#1\x9bm  is a color number in [0..9] \n");
  52.       printf("\t     \x9b2mt\x9bm   is one of \x9b2ml\x9bm (line) or \x9b2mp\x9bm (point)\n");
  53.       printf("\t     \x9b2m#2\x9bm  is a point size in [1..10]\n\n");
  54.       printf("\tEXAMPLE:  \x9b2m/gt5 - 0p4 1l - - 2p 3l\x9bm\n\n");
  55.       printf("Enter \x9b2mhow_to string\x9bm (? for help) > ");
  56.       sp = gets(s);
  57.    }
  58.  
  59.    if (*sp=='/') {
  60.       sp++;
  61.       while ( (*sp) && (*sp != ' ') ) {
  62.          switch (*sp++) {
  63.             case 'd': debug = TRUE; printf("*** debug on ***\n"); break;
  64.             case 'D': debug = FALSE; break;
  65.             case 'g': Pict->Grid = TRUE; break;
  66.             case 'G': Pict->Grid = FALSE; break;
  67.             case 'e': Pict->ShowErr = Pict->ErrBar; break;
  68.             case 'E': Pict->ShowErr = FALSE; break;
  69.             case 't':
  70.                Pict->Tics->NX = atoi(sp);
  71.                Pict->Tics->NY = Pict->Tics->NX;
  72.                sp++;
  73.                break;
  74.             default: break;
  75.          }
  76.       }
  77.    }
  78.    
  79.    while (*sp==' ') sp++;
  80.    if (!(*sp) || (*sp=='!')) {
  81.  
  82.       Plot = Pict->Plot;
  83.       i = 0;
  84.       while (Plot) {
  85.          Plot->Enabled = TRUE;
  86.          Plot->Color = PLOTCOLORBASE + i;
  87.          if ((*sp=='!') && (sp[1]=='p')) {
  88.             if (isdigit(sp[2]))
  89.                Plot->PointSize = atoi(&sp[2]);
  90.             else if (sp[2]=='-')
  91.                Plot->PointSize = 
  92.                      (isdigit(sp[3]) ? atoi(&sp[2]) : -DEFAULT_POINT_SIZE);
  93.             else
  94.                Plot->PointSize = DEFAULT_POINT_SIZE;
  95.          }
  96.          else
  97.             Plot->PointSize = 0;
  98.  
  99.          while (Plot->Continued) {
  100.             Plot->NextPlot->Color = Plot->Color;
  101.             Plot->NextPlot->PointSize = Plot->PointSize;
  102.             Plot->NextPlot->Enabled = Plot->Enabled;
  103.             Plot = Plot->NextPlot;
  104.          } 
  105.          Plot = Plot->NextPlot;
  106.          i++;
  107.       }
  108.    }
  109.    
  110.    else {
  111.       /* INIT ALL PLOTS TO "DISABLED" */
  112.       Plot = Pict->Plot;
  113.       while (Plot) {Plot->Enabled = FALSE; Plot = Plot->NextPlot;}
  114.  
  115.       /* GET USER'S INSTRUCTIONS FOR EACH PLOT */
  116.       Plot = Pict->Plot;
  117.       i = 0;
  118.       while( *(wp=getwrd(&sp)) && Plot) {
  119.          if (*wp == '-')
  120.             Plot->Enabled = FALSE;
  121.          else {
  122.             Plot->Enabled = TRUE;
  123.             if (isdigit(*wp))
  124.                {Plot->Color = PLOTCOLORBASE + atoi(wp); wp++;}
  125.             else
  126.                Plot->Color = PLOTCOLORBASE + i;
  127.  
  128.             if (*(wp++) == 'p') {
  129.                if (isdigit(*wp))
  130.                   Plot->PointSize = atoi(wp);
  131.                else if (*wp=='-')
  132.                   Plot->PointSize = 
  133.                      (isdigit(wp[1]) ? atoi(wp) : -DEFAULT_POINT_SIZE);
  134.                else
  135.                   Plot->PointSize = DEFAULT_POINT_SIZE;
  136.             }
  137.             else
  138.                Plot->PointSize = 0; /* GETS LINE PLOT */
  139.          }
  140.  
  141.          while (Plot->Continued) {
  142.             Plot->NextPlot->Color = Plot->Color;
  143.             Plot->NextPlot->PointSize = Plot->PointSize;
  144.             Plot->NextPlot->Enabled = Plot->Enabled;
  145.             Plot = Plot->NextPlot;
  146.          } 
  147.          Plot = Plot->NextPlot;
  148.          i++;
  149.       }
  150.    }
  151.    if (debug) printf("GetHowTo: exit\n");
  152. }
  153.